var course1 = null;
var course2 = null;

// This function is run once to setup the game.
function start() {
  racecar = new Car;
  racecar.moveTo(start1);
  keys = new Keys;
  // TODO, WRITE THE createCourse FUNCTION
  // BELOW SO THAT THIS WORKS!
  var start1 = "111 8th Ave, NYC";
  var start2 = "20 W 85th, NYC";
  var finishAddress = "364 W. 18th, NYC";
  course1 = createCourse(start1, finishAddress);
  course2 = createCourse(start2, finishAddress);
}

// MAKE YOUR createCourse function here!!
function createCourse(start, finish) {
  var cool = new Course;
  cool.setStart(start);
  cool.setFinish(finish);
  return cool;
}

// This function updates the game screen for animation.
function everyFrame() {
  handleKeys();
}

function handleKeys() {
  if (keys.upIsPressed()) {
    racecar.accelerate();
  } else if (keys.downIsPressed()) {
    racecar.decelerate();
  }
  if (keys.leftIsPressed()) {
    racecar.turnLeft();
  } else if (keys.rightIsPressed()) {
    racecar.turnRight();
  }
  if (keys.spaceIsPressed()) {
    racecar.jump(10);
  }
  if (keys.isPressed('a')) {
    racecar.jump(10);
  }
  if (keys.isPressed('1')) {
    racecar.moveToCourseStart(course1);
  } else if (keys.isPressed('2')) {
    racecar.moveToCourseStart(course2);
  }
}
